#pragma once

#include "../../vmath/vec2.h"

OPEN_JLIB_NS


struct MouseEvent {

  enum Button : u32 {
    Unknown   = 0,
    Button_1  = 1,             Left = Button_1,
    Button_2  = Button_1 << 1, Right = Button_2,
    Button_3  = Button_2 << 1, Middle = Button_3,
    Button_4  = Button_3 << 1, Extra_1 = Button_4, Forward = Button_4,
    Button_5  = Button_4 << 1, Extra_2 = Button_5, Backward = Button_5,
    Button_6  = Button_5 << 1, Extra_3 = Button_6,
    Button_7  = Button_6 << 1, Extra_4 = Button_7,
    Button_8  = Button_7 << 1, Extra_5 = Button_8,
    Button_9  = Button_8 << 1, Extra_6 = Button_9,
    Button_10 = Button_9 << 1, Extra_7 = Button_10,
    Button_11 = Button_10 << 1, Extra_8 = Button_11,
    Button_12 = Button_11 << 1, Extra_9 = Button_12,
    Button_13 = Button_12 << 1, Extra_10 = Button_13,
    Button_14 = Button_13 << 1, Extra_11 = Button_14,
    Button_15 = Button_14 << 1, Extra_12 = Button_15,
  };

  inline void setLocation (const vec2 &location) noexcept { this->_location = location; }
  inline void setButton (int button) noexcept { this->_button = button; }
  inline void setScroll (int scroll) noexcept { this->_scroll = scroll; }
  inline void appendStates (int button) noexcept { this->_states |= button; }
  inline void removeStates (int button) noexcept { this->_states &= ~button; }

  inline vec2 getLocation () const noexcept { return this->_location; }
  inline int getButton () const noexcept { return this->_button; }
  inline int getScroll () const noexcept { return this->_scroll; }
  inline bool isButtonPressed (int button) const noexcept { return (this->_states & button) != 0; }

  vec2 _location {0, 0};
  int _button;
  int _scroll;
  int _states {0};
  friend struct MouseManager;
};


CLOSE_JLIB_NS
